package conceptmaniax.hotelapp.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import conceptmaniax.hotelapp.activities.R;
import conceptmaniax.hotelapp.pojos.Service;

public class FeedbackListAdapter extends BaseAdapter implements OnClickListener {
    
	private Context context;
    private List<Service> serviceList;

	public List<Service> getServiceList() {
		return serviceList;
	}

	public void setServiceList(List<Service> serviceList) {
		this.serviceList = serviceList;
	}

	public FeedbackListAdapter() {
    	super();
    }
    
    public FeedbackListAdapter(final Context context, final List<Service> serviceList) {
    	super();
    	this.context = context;
        this.serviceList = serviceList;
    }

    public int getCount() {
        return serviceList.size();
    }

    public Object getItem(final int position) {
        return serviceList.get(position);
    }

    public long getItemId(final int position) {
        return position;
    }

    public View getView(final int position, View convertView, final ViewGroup viewGroup) {
        final Service item = serviceList.get(position);
        
        if (convertView == null) {
            final LayoutInflater feedInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = feedInflater.inflate(R.layout.feedback_row, null);
        }
       
        final TextView itemName = (TextView) convertView.findViewById(R.id.item_title);
        itemName.setText(item.getName());
            
        return convertView;
    }

    @Override
    public void onClick(final View view) {
        final Service entry = (Service) view.getTag();
        serviceList.remove(entry);
        notifyDataSetChanged();
    }
}
